#!/bin/ksh

echo "Please input the DATE of Backup!!"
echo "The Date format is: yyyymmdd"
echo "Press enter directly is to show Today's Backup logs"
read MYDATE

TEST=mytest$MYDATE

MYYEAR=`expr substr "$MYDATE" 3 4` 
MYMONTH=`expr substr "$MYDATE" 5 2` 
MYDAY=`expr substr "$MYDATE" 7 2` 

if [ $TEST = mytest ];then
  Serach_date=`date +%m`/`date +%d`/`date +%Y`
else 
  Serach_date=${MYMONTH}/${MYDAY}/${MYYEAR}
fi

LOG=/opt/tivoli/tsm/client/log/dsmsche.log
grep "^$Serach_date" $LOG > /tmp/CKBackup1.log
grep -v "Normal File-" /tmp/CKBackup1.log | grep -v ANS1898I | grep -v "Expiring-->" | grep -v "Directory-->" >/tmp/tsmbackup.log 
TEST1=`grep -c "Successful incremental backup of" /tmp/tsmbackup.log`
if [ $TEST1 -gt 0 ]
then
  echo "                                      "
  echo " ******** Backup Sucessfully ******** "
  echo "                                      "
  echo " The Detail Information as  following "
  echo "                                      "
  LineBegin=`sed -n '/SCHEDULEREC OBJECT BEGIN SH_CRM_BI_SCHE/=' /tmp/tsmbackup.log`
  LineEnd=`sed -n '/SCHEDULEREC OBJECT END SH_CRM_BI_SCHE/=' /tmp/tsmbackup.log`
  sed -n "${LineBegin},${LineEnd}p"  /tmp/tsmbackup.log
else
  echo "                                      "
  echo " ****** Backup May Have Error  ****** "
  echo " ****  Or Backup Is Running now ***** "
  echo "                                      "
  echo "                                      "
  echo "****** Do You Want To See Detail ********"
  echo "****** Press Yes(y) to See Detail *******"
  read MYYES
  case  $MYYES in
    Y|y)cat /tmp/tsmbackup.log |more
        echo 
	echo
    ;;
    *) exit
    ;;
   esac 
fi
